package com.example.xianji.activity;

import android.os.Bundle;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.xianji.Contant;
import com.example.xianji.R;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;

public class Main_GeRen_ZhongXinActivity extends Activity implements OnClickListener {
    private RelativeLayout jiben_xinxi;
//    private RelativeLayout relativelayout_geren_renzheng;
    private RelativeLayout set_up_geren_logo, shezhi_geren_zizhi;
    private RelativeLayout geren_zhongxin_back, geren_zhongxin_relative_delete;
    //    private SharedPreferences sp;
//    private Editor ed;
    private TextView geren_zhongxin_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__ge_ren__zhong_xin);

        //XJApplication.getInstance4().addActivity4(this);
        jiben_xinxi = (RelativeLayout) findViewById(R.id.jiben_xinxi);
        geren_zhongxin_back = (RelativeLayout) findViewById(R.id.geren_zhongxin_relative_back);
//        relativelayout_geren_renzheng = (RelativeLayout) findViewById(R.id.relativelayout_geren_renzheng);
        set_up_geren_logo = (RelativeLayout) findViewById(R.id.set_up_geren_logo);
        geren_zhongxin_title = (TextView) findViewById(R.id.geren_zhongxin_title);

        shezhi_geren_zizhi = (RelativeLayout) findViewById(R.id.shezhi_geren_zizhi);
        geren_zhongxin_relative_delete = (RelativeLayout) findViewById(R.id.geren_zhongxin_relative_delete);

//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();
        if (PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("FC") ||
                PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("AC")) {
//        if (sp.getString("xianji_type", "").equals("FC") || sp.getString("xianji_type", "").equals("AC")) {
            geren_zhongxin_title.setText("企业简介");
        } else {
            geren_zhongxin_title.setText("个人简介");
        }
        jiben_xinxi.setOnClickListener(this);
        geren_zhongxin_back.setOnClickListener(this);
//        relativelayout_geren_renzheng.setOnClickListener(this);
        set_up_geren_logo.setOnClickListener(this);
        shezhi_geren_zizhi.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.jiben_xinxi) {
            if (PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("FC") ||
                    PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("AC")) {
//            if (sp.getString("xianji_type", "").equals("FC") || sp.getString("xianji_type", "").equals("AC")) {
                startActivity(new Intent(Main_GeRen_ZhongXinActivity.this, Main_QiYe_informationActivity.class));
            } else {
                Intent intent = new Intent(Main_GeRen_ZhongXinActivity.this, Main_InformationActivity.class);
                startActivityForResult(intent, Contant.requestCode);
            }

        } else if (v.getId() == R.id.geren_zhongxin_relative_back) {
            this.setResult(Contant.back_resultCode);
            this.finish();
//        } else if (v.getId() == R.id.relativelayout_geren_renzheng) {
//            Intent intent = new Intent(Main_GeRen_ZhongXinActivity.this, Main_MyRengZhengActivity.class);
//            startActivityForResult(intent, Contant.renzheng_requestCode);
        } else if (v.getId() == R.id.set_up_geren_logo) {
            Intent intent = new Intent(Main_GeRen_ZhongXinActivity.this, Main_set_up_photoActivity.class);
            startActivityForResult(intent, Contant.photo_requestCode);
        } else if (v.getId() == R.id.shezhi_geren_zizhi) {
            Intent intent = new Intent(Main_GeRen_ZhongXinActivity.this, Main_ZiZhiActivity.class);
            startActivityForResult(intent, Contant.zizhi_requestCode);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Contant.requestCode && resultCode == Contant.back_resultCode) {
            geren_zhongxin_relative_delete.setVisibility(View.VISIBLE);
            geren_zhongxin_relative_delete.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Main_GeRen_ZhongXinActivity.this.setResult(Contant.delete_resultCode);
                    Main_GeRen_ZhongXinActivity.this.finish();
                }
            });

        } else if (requestCode == Contant.requestCode && resultCode == Contant.delete_resultCode) {
            Main_GeRen_ZhongXinActivity.this.setResult(Contant.delete_resultCode);
            Main_GeRen_ZhongXinActivity.this.finish();

        } else if (requestCode == Contant.photo_requestCode && resultCode == Contant.delete_resultCode) {
            Main_GeRen_ZhongXinActivity.this.setResult(Contant.delete_resultCode);
            Main_GeRen_ZhongXinActivity.this.finish();
        } else if (requestCode == Contant.photo_requestCode && resultCode == Contant.back_resultCode) {
            geren_zhongxin_relative_delete.setVisibility(View.VISIBLE);
            geren_zhongxin_relative_delete.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Main_GeRen_ZhongXinActivity.this.setResult(Contant.delete_resultCode);
                    Main_GeRen_ZhongXinActivity.this.finish();
                }
            });
        } else if (requestCode == Contant.renzheng_requestCode && resultCode == Contant.back_resultCode) {
            geren_zhongxin_relative_delete.setVisibility(View.VISIBLE);
            geren_zhongxin_relative_delete.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Main_GeRen_ZhongXinActivity.this.setResult(Contant.delete_resultCode);
                    Main_GeRen_ZhongXinActivity.this.finish();
                }
            });
        } else if (requestCode == Contant.zizhi_requestCode && resultCode == Contant.back_resultCode) {
            geren_zhongxin_relative_delete.setVisibility(View.VISIBLE);
            geren_zhongxin_relative_delete.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Main_GeRen_ZhongXinActivity.this.setResult(Contant.delete_resultCode);
                    Main_GeRen_ZhongXinActivity.this.finish();
                }
            });
        }
    }
}
